package demo.axitdn.model;

import demo.axitdn.physic.CircularMotion;
import demo.axitdn.physic.Force;
import demo.axitdn.physic.Vector3f;
import demo.axitdn.physic.ZeroForce;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Region;
import android.view.MotionEvent;

public class DemoModel extends Model {
	private float radius;
	private Force motion;
	private int color;
	private MotionEvent downEvent;
	private MotionEvent upEvent;
	private boolean isDown;
	public DemoModel(Vector3f p0,Vector3f v0) {
		super();
		state.position=p0;
		state.velocity=v0;
		radius=15;
		color=Color.YELLOW;
	}
	public DemoModel(float x0,float y0,float v0,float angle,double t,float radius) {
		super();
		this.radius=radius;
		state.position.x=x0;
		state.position.y=y0;
		state.velocity.x= (float) (v0 * Math.cos(angle));
		state.velocity.y= (float) (v0 * Math.sin(angle));
		motion=new ZeroForce();
		this.setForce(motion);
		color=Color.RED;
	}
	@Override
	public void onDraw(Canvas c) {
		// TODO Auto-generated method stub
		Paint p=new Paint();
		p.setColor(color);
		int x=(int)(state.position.x*30);
        int y=(int)(state.position.y*30);
		c.drawCircle(x, y, radius, p);		
	}
	@Override
	public void onUpdate(double t) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		super.onTouchEvent(event);
		int x=(int) event.getX();
		int y=(int) event.getY();
		Region r=new Region((int)(state.position.x*30-radius), (int)(state.position.y*30-radius),(int)( state.position.x*30+radius), (int)(state.position.y*30+radius));
		boolean isOn=r.contains(x, y);
		if(isOn) {
			if(event.getAction()==MotionEvent.ACTION_DOWN) {
				color=Color.GREEN;
				downEvent=MotionEvent.obtain(event);	
				isDown=true;
			}
			if(event.getAction()==MotionEvent.ACTION_UP) {
				color=Color.RED;
				upEvent=MotionEvent.obtain(event);
				isDown=false;
			}
		}
		if(isDown) {
			if(event.getAction()==MotionEvent.ACTION_MOVE) {
				color=Color.BLUE;
			}
			if(event.getAction()==MotionEvent.ACTION_UP) {
				color=Color.RED;
				upEvent=MotionEvent.obtain(event);
				isDown=false;
			}
		}
		return true;
	}

}
